//
//  NSBundle+OMTImagePicker.m
//  OMTImagePicker
//
//  Created by yizhaorong on 2018/1/12.
//

#import "NSBundle+OMTImagePicker.h"
#import "OMTAlbumManager.h"

@implementation NSBundle (OMTImagePicker)

+ (NSBundle *)omt_imagePickerBundle {
    static NSBundle *bundle;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSBundle *classBundle = [NSBundle bundleForClass:[OMTAlbumManager class]];
        NSURL *url = [classBundle URLForResource:@"OMTImagePicker" withExtension:@"bundle"];
        bundle = [NSBundle bundleWithURL:url];
    });
    return bundle;
}

+ (NSString *)omt_localizedStringForKey:(NSString *)key {
    static NSBundle *bundle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSString *language = [NSLocale preferredLanguages].firstObject;
        bundle = [NSBundle bundleWithPath:[[NSBundle omt_imagePickerBundle] pathForResource:language ofType:@"lproj"]];
        if (!bundle) {
            language = @"ar";
            bundle = [NSBundle bundleWithPath:[[NSBundle omt_imagePickerBundle] pathForResource:language ofType:@"lproj"]];
        }
    });
    NSString *value = [bundle localizedStringForKey:key value:key table:nil];
    return value;
}

@end
